import 'package:aio/aio.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:app/generated/app_strings.dart';
import 'package:app/src/config/app_data_config.dart';
import 'package:app/src/http/bean/wroks/search_bean.dart';
import 'package:app/src/ui/app_ui.dart';
import 'package:app/src/http/bean/ywx_limit.dart';
import 'package:app/src/ui/popuwindow/popuwindow_search.dart';
import 'package:app/src/ui/route/works/public/review_list.dart';

import '../../../../manager/ywx_manager.dart';

///请购单审核
class MaterialRequisitionAuditRoute extends StatefulWidget {
  YwxItem item;

  MaterialRequisitionAuditRoute(this.item);

  @override
  _State createState() => _State();
}

class _State extends State<MaterialRequisitionAuditRoute> {
  _Presenter presenter = _Presenter();

  @override
  void initState() {
    super.initState();
    if (presenter.searchInfo == null) {
      presenter.searchInfo = SearchInfo(widget.item)
        ..isShowStatus = true //审核状态
        ..isShowStatusAll = false //审核状态不具备全显示
        ..isShowPurchaseOrderNumber = true //请购单号
        ..isShowContractCode = true //合同编号(销售合同号)
        ..isShowMaterialName = true //物料名称
        ..isShowTypeOfMaterial = false //fixme 物料类型
        ..isShowBrand = true //品牌
        ..isShowSupplier = true //供应商
        ..isShowDept = true //部门
        ..isShowProjectName = true //项目名称
        ..isShowSize = true //规格
        ..isShowPurStartDate = true //采购申请日期
        ..isShowPurEndDate = true //采购要货日期
        ..isShowPurchaseStatus = true //请购单状态
        ..isShowFounder = true //创建人
        ..isShowAddTime = false; //
    }
    if (widget.item.ReviewType == ReviewType.GetPurDemandListMT02) {
      //辅料请购单审核
      presenter.searchInfo?.MaterialType = "MT02";
    } else if (widget.item.ReviewType == ReviewType.GetPurDemandListMT03) {
      //五金请购单审核
      presenter.searchInfo?.MaterialType = "MT03";
    } else {
      //原片请购单审核
      presenter.searchInfo?.MaterialType = "";
    }
  }

  @override
  Widget build(BuildContext context) {
    px.init(context);
    presenter.searchInfo?.showAddTime = AppStrings.of(context).AddDate; //申请时间
    presenter.searchInfo?.showContractCodeName =
        AppStrings.of(context).ContractCode2; //销售合同号
    presenter.searchInfo?.showPurchaseStatusName =
        AppStrings.of(context).PurchaseStatus; //请购单状态
    var scaffold = AppUi.getScaffoldWithReView(
        context, _body(context), widget.item, presenter.searchInfo!, () {
      //print("===============================================================搜索刷新");
      presenter.setStateBody?.call(() {});
    });
    return WillPopScope(
      child: scaffold,
      onWillPop: () async {
        return true; //true 不屏蔽返回键
      },
    );
  }

  Widget _body(BuildContext context) {
    //print("===============================================================页面刷新:$isShowPopuMenuWithSearch");
    return StatefulBuilder(
        builder: (BuildContext context, StateSetter setState) {
      presenter.setStateBody = setState;
      List<Widget> children = [];
      //搜索条件
      var searchLayout =
          AppUi.getSearchLayout(context, presenter.searchInfo!, () {
        presenter.setStateBody?.call(() {});
      });
      children.add(searchLayout);
      //审核列表
      var reviewList = ReviewList(widget.item, presenter.searchInfo!, true);
      children.add(Expanded(child: reviewList));
      return Column(
        children: children,
      );
    });
  }
}

class _Presenter {
  ///搜索条件
  SearchInfo? searchInfo = null;

  ///body视图状态
  StateSetter? setStateBody;
}
